import {
    ListViewActionType,
    IListViewAbility,
    IListViewController,
    IListViewControllerParams,
    IListViewModel,
    IListViewStore,
    IParam,
    IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
    getViewClassNames,
    handleQuickGroupValueChange,
    useViewAction,
    useViewBasic,
    useViewControllerParams,
    useViewProps,
} from '../use-view';

/**
 * 获取列表视图输入参数
 *
 * @export
 * @return {*}
 */
export function useListViewProps() {
    return {
        ...useViewProps(),
    };
}

/**
 * 获取列表视图基础
 *
 * @export
 * @param {IListViewModel} model 列表视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useListViewBasic(model: IListViewModel, props: IParam) {
    const getSearchFormSlotName = (props: IParam) => {
        const showTabPageExp = App.getProjectSetting().multiTabsSetting.show;
        let searchFormSlotName = 'viewHeaderTop';
        if (!showTabPageExp && props.openType == 'ROUTE') {
            searchFormSlotName = 'viewHeaderBottom';
        }
        return searchFormSlotName;
    }
    const getClassNames = (props: IParam) => {
        return getViewClassNames(model, props)
    }
    return {
        ...useViewBasic(model, props),
        getClassNames,
        getSearchFormSlotName,
        handleQuickGroupValueChange,
    };
}

/**
 * 列表视图行为
 *
 * @export
 */
export function useListViewAction(controller: IListViewController<IListViewStore, IListViewAbility>) {
    return {
        ...useViewAction(controller)
    };
}

/**
 * 获取列表视图控制器输入参数
 *
 * @export
 * @param {IListViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<ListViewActionType, IListViewAbility>>} evt
 * @return {*}  {IListViewControllerParams<ListViewActionType, IListViewAbility>}
 */
export function useListViewControllerParams(
    model: IListViewModel,
    props: IParam,
    evt: QXEvent<IViewEvent<ListViewActionType, IListViewAbility>>
): IListViewControllerParams<ListViewActionType, IListViewAbility> {
    return {
        ...useViewControllerParams<IListViewStore, IListViewModel>(
            model,
            props,
            evt
        ),
    };
}
